﻿using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;

namespace Eneta.Portal.Companies
{
    public static class Utility
    {
        public static string Nl2Br(this string instr)
        {
            return instr.Replace("\n", "<br/>").Replace("\r", string.Empty);
        }
        public static List<ListItem> SelectedItems(this CheckBoxList checkList)
        {
            var items = new List<ListItem>();
            foreach (ListItem item in checkList.Items)
                if (item.Selected)
                    items.Add(item);

            return items;
        }
        
        public static byte[] ToWindows1257(this string input)
        {
            if (string.IsNullOrEmpty(input))
                return new byte[] { };


            var defaultEncoding = Encoding.UTF8;
            var asciiEncoding = Encoding.GetEncoding("windows-1257");
            var bytes = defaultEncoding.GetBytes(input);

            return Encoding.Convert(defaultEncoding, asciiEncoding, bytes);
        }
    }
}
